package com.story.web.controllers;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.story.domain.Page;
import com.story.domain.User;
import com.story.service.IUserService;
@Controller
@RequestMapping("/manager/user")
public class UserManagerController {

	@Autowired
	private IUserService userService;

	// 分页展示User数据
	@RequestMapping("/page/show")
	@ResponseBody
	public Object showUsers(Integer pageNum, Integer pageSize) {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		if (pageNum == null || pageSize == null) {
			return null;
		}
		Page page = new Page(pageNum, pageSize);
		Integer total = userService.userTotal();
		List<User> userList = userService.findUsersByLimit(page);
		map.put("code", 0);
		map.put("msg", "查询成功！");
		map.put("count", total);
		map.put("data", userList);
		return map;
	}

	@RequestMapping("/{id}/show")
	public String showUser(@PathVariable("id") String id, Model model) {
		model.addAttribute("id", id);
		return "manager/showUser";
	}

	@RequestMapping("/delete")
	public String deleteUser() {
		return "aaaa";
	}
}
